package com.easy.dev.utils;

import com.baomidou.mybatisplus.annotation.TableField;
import com.easy.dev.annotation.Bind;
import org.springframework.util.StringUtils;

import java.lang.reflect.Field;

public class FieldUtils {

    public static String getSqlFieldName(Field field) {
        TableField tableField = field.getAnnotation(TableField.class);
        if (tableField == null) {
            return field.getName();
        }
        return tableField.value();
    }

    public static String getSqlFieldName(Field field, boolean join, Bind bind) {
        if (join) {
            if (bind != null) {
                return StringUtils.isEmpty(bind.realAsColumn())?bind.realColumn():bind.realColumn() +" as " +bind.realAsColumn();
            }
        }
        return getSqlFieldName(field);
    }

}
